//
//  MainViewController.m
//  ZSMiao
//
//  Created by zsj1992 on 16/12/1.
//  Copyright © 2016年 bjhj. All rights reserved.
//

#import "MainViewController.h"
#import "ZSHomeViewController.h"
#import "ZSLiveViewController.h"
#import "ZSMyViewController.h"
#import "ZSNavigationController.h"

#import "ZSTabBar.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //添加子控制器
    
    [self addChildVcs];
    
    

}


-(void)addChildVcs{

    ZSHomeViewController * homeVc = [[ZSHomeViewController alloc]init];
    [self addChildVc:homeVc title:@"首页" image:@"toolbar_home1" selectedImage:@"toolbar_home_sel1"];
    
    ZSLiveViewController * liveVc = [[ZSLiveViewController alloc]init];
    [self addChildVc:liveVc title:@"Miao" image:@"toolbar_live1" selectedImage:@""];
    
    ZSMyViewController * myVc = [[ZSMyViewController alloc]init];
    [self addChildVc:myVc title:@"我的" image:@"toolbar_me1" selectedImage:@"toolbar_me_sel1"];

    ZSTabBar *tabBar = [[ZSTabBar alloc] init];
    tabBar.delegate = self;
    // KVC：如果要修系统的某些属性，但被设为readOnly，就是用KVC，即setValue：forKey：。
    [self setValue:tabBar forKey:@"tabBar"];

}





- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置子控制器的文字(可以设置tabBar和navigationBar的文字)
    childVc.title = title;
    
    // 设置子控制器的tabBarItem图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    // 禁用图片渲染
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置文字的样式
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : RGBA(123, 123, 123,1)} forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateSelected];
    //    childVc.view.backgroundColor = RandomColor; // 这句代码会自动加载主页，消息，发现，我四个控制器的view，但是view要在我们用的时候去提前加载
    
    // 为子控制器包装导航控制器
    ZSNavigationController *navigationVc = [[ZSNavigationController alloc] initWithRootViewController:childVc];
    // 添加子控制器
    [self addChildViewController:navigationVc];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
